package com.hy.erp.inventory.service;

import java.util.List ;

import javax.ejb.Stateless ;

import org.jboss.seam.ScopeType ;
import org.jboss.seam.annotations.Name ;
import org.jboss.seam.annotations.Scope ;
import org.jboss.seam.async.Schedule ;

import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.interfaces.IRoleDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.Role;
import com.hy.erp.inventory.pojo.interfaces.IRole;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IRoleService;

/**
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-12；时间：下午04:08:32</li>
 * <li>字段类型：long；字段名称：serialVersionUID</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
@Name("roleService")
@Scope(ScopeType.SESSION)
@Stateless
public class RoleService
						extends
						AbstractBusinessService < IRole >
																implements
																IRoleService
{

	private static final long	serialVersionUID	=
														- 765412174631003443L ;
	/**
	 * 
	 * 构造函数
	 */
	public RoleService()
	{
		super ( );
	}
	@ Override
	public String[] addRole (
								IRole[] role )
	{
		if(role==null)
		{
			return null;
		}
		else
		{
			IRoleDao dao=( IRoleDao ) this.getDao ( IRole.class );
//			IRole iRole=role;
			return dao.persist ( role ) ;
		}
	}

	@ Override
	public Integer removeRole (
								String [ ] roleIds )
	{
		if ( ( null == roleIds )
			     || ( roleIds.length == 0 ) )
			{
				return new Integer (
				                     0 ) ;
			}
			else
			{
				IRoleDao dao=( IRoleDao ) this.getDao ( IRole.class );
				return dao.remove ( roleIds );
			}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyRole (
								Role role )
	{
		if ( ( null == role ) || ( null == role.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			IRoleDao dao=( IRoleDao ) this.getDao ( IRole.class );
			IRole iRole=role;
			
			if ( null == iRole )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (dao.merge ( iRole )!=null) ;
		}
	}
	@ Override
	public List < IRole > getRoleById (
										String [ ] Id )
	{
		if((Id.length!=0)||Id!=null)
		{
			IRoleDao dao=( IRoleDao ) this.getDao ( IRole.class );
			dao.findByIdentifier ( Id );
		}
		return null ;
	}

}
